<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2008 XBRL International. All Rights Reserved. -->
<?xml-stylesheet type="text/xsl" href="../stylesheets/conformanceFunction.xsl"?>
<testcase
  xmlns="http://xbrl.org/2008/conformance"
  xmlns:reg="http://xbrl.org/2008/registry"
  xmlns:fcn="http://xbrl.org/2008/function"
  xmlns:cfcn="http://xbrl.org/2008/conformance/function"
  xmlns:xbrli="http://www.xbrl.org/2003/instance"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:xfi="http://www.xbrl.org/2008/function/instance"
  xmlns:xfie="http://www.xbrl.org/2008/function/instance/error"
  xmlns:xqt-err="http://www.w3.org/2005/xqt-errors"
  xmlns:concept="http://xbrl.org/formula/conformance/example" 
  xmlns:test="http://abc.com/test"
  xmlns:test1="http://abc.com/test1"
  xmlns:test2="http://abc.com/test2"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xsi:schemaLocation="
  http://xbrl.org/2008/registry ../schemas/registry.xsd
  http://xbrl.org/2008/function ../schemas/function.xsd
  http://xbrl.org/2008/conformance ../schemas/conformance.xsd
  http://xbrl.org/2008/conformance/function ../schemas/conformanceFunction.xsd
  ">
  <owners>
    <reg:owner id="herm">
      <reg:name>Herm Fischer</reg:name>
      <reg:affiliation>UBMatrix / Mark V Systems</reg:affiliation>
      <reg:email>fischer@markv.com</reg:email>
     <reg:assumedOwnership moment="2008-12-12T00:00:00" />
    </reg:owner>
  </owners>

  <number>90601</number>

  <name>Function test for xfi:xbrl-instance</name>

  <documentation>
    <xhtml:p>
      Tests of function xfi:xbrl-instance($href as xs:anyURI) as element(xbrli:xbrl)
      </xhtml:p>
    <xhtml:p>
      Please see the examples and formula-testcase-based variations in the companion file, which is in the formula testcase format, <xhtml:a href="90601 xfi.xbrl-instance formula testcase.xml">90601 xfi.xbrl-instance formula testcase.xml</xhtml:a>
    </xhtml:p>
  </documentation>

  <reference xlink:type="simple" xlink:href="http://www.xbrl.org/Specification/XF-PWD-2006-12-07.htm#_Toc152670666"/>

  <variation id="V-01">
    <name>Load specified XBRL instance</name>
    <documentation>
      <xhtml:p>
        Loaded instance and target instance have different target namespaces.
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1.xsd"/>
      <instance readMeFirst="true" id="V01" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V01">
        xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         count( $result ) eq 1 and
         node-name($result) eq QName('http://www.xbrl.org/2003/instance','xbrl') and
         count( $result/*[namespace-uri() eq 'http://abc.com/test1'] ) eq 0 and
         count( $result/*[namespace-uri() eq 'http://abc.com/test2'] ) eq 18 and
         count( //*[namespace-uri() eq 'http://abc.com/test1'] ) eq 18 and
         count( //*[namespace-uri() eq 'http://abc.com/test2'] ) eq 0
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-02">
    <name>Facts of loaded XBRL instance have PSVI type</name>
    <documentation>
      <xhtml:p>
        Loaded instance and target instance have different target namespaces.
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1.xsd"/>
      <instance readMeFirst="true" id="V02" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V02">
        xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
          data($result/test2:A) instance of xs:decimal and
         ($result/test2:A + $result/test2:A1 + $result/test2:A11) eq 12080400
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-03">
    <name>Terms from instances inter-mixable in XPath expression</name>
    <documentation>
      <xhtml:p>
        Loaded instance and target instance have different target namespaces.
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1.xsd"/>
      <instance readMeFirst="true" id="V03" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V03">
        xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         (//test1:A + $result/test2:A + //test1:A1 + $result/test2:A1 + //test1:A11 + $result/test2:A11) eq 15100500
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-04">
    <name>XPath functions from instances inter-mixable in XPath expression</name>
    <documentation>
      <xhtml:p>
        Loaded instance and target instance have different target namespaces.
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1.xsd"/>
      <instance readMeFirst="true" id="V04" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V04">
        xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         node-name(//test1:A) eq QName('http://abc.com/test1','A') and
         node-name(//test1:A1) eq QName('http://abc.com/test1','A1') and
         node-name(//test1:A11) eq QName('http://abc.com/test1','A11') and
         node-name($result/test2:A) eq QName('http://abc.com/test2','A') and
         node-name($result/test2:A1) eq QName('http://abc.com/test2','A1') and
         node-name($result/test2:A11) eq QName('http://abc.com/test2','A11')
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-05">
    <name>xfi functions from instances inter-mixable</name>
    <documentation>
      <xhtml:p>
        Loaded instance and target instance have different target namespaces.
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1.xsd"/>
      <instance readMeFirst="true" id="V05" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V05">
        xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         xfi:period-instant( xfi:period( (//test1:A) ) ) eq xs:dateTime("2000-12-31T24:00:00") and
         xfi:period-instant( xfi:period( ($result/test2:A) ) ) eq xs:dateTime("2001-12-31T24:00:00")
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-06">
    <name>xfi relationship navigation of instances inter-mixable</name>
    <documentation>
      <xhtml:p>
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1.xsd"/>
      <instance readMeFirst="true" id="V06" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V06">
        xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         count(xfi:navigate-relationships(
                QName('http://abc.com/test1','A'), 
                'http://abc.com/role/link1',
                'http://abc.com/arcrole/def-test',
                'descendant',
                1)) eq 3 and
         count(xfi:navigate-relationships(
                QName('http://abc.com/test2','A'), 
                'http://abc.com/role/link1',
                'http://abc.com/arcrole/def-test',
                'descendant',
                1,(),$result)) eq 3 and
         (every $rel in 
             xfi:navigate-relationships(
                QName('http://abc.com/test1','A'), 
                'http://abc.com/role/link1',
                'http://abc.com/arcrole/def-test',
                'descendant',
                1) 
           satisfies namespace-uri-from-QName($rel) eq 'http://abc.com/test1') and
         (every $rel in 
             xfi:navigate-relationships(
                QName('http://abc.com/test2','A'), 
                'http://abc.com/role/link1',
                'http://abc.com/arcrole/def-test',
                'descendant',
                1,(),$result) 
           satisfies namespace-uri-from-QName($rel) eq 'http://abc.com/test2')
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-07">
    <name>DTSes can share file but keep DTS linkbases separate</name>
    <documentation>
      <xhtml:p>
        Loaded instance and target instance have same schema xsd file but different label linkbases.
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1c.xsd"/>
      <instance readMeFirst="true" id="V07" xlink:type="simple" xlink:href="xbrl-inst-detached-labels-instance1-no-formula.xml"/>
     <cfcn:call file="V07">
        for $inst2 in xfi:xbrl-instance('xbrl-inst-detached-labels-instance2.xml')
        return (
         (: node provides correct instance for function to select right DTS and label :)
         xfi:concept-label( node-name (//test:A),'','','en' ),
         xfi:concept-label( node-name ($inst2/test:A),'','','en', $inst2 ),

         (: target instance DTS for label :)
         xfi:concept-label( QName('http://abc.com/test','A'),'','','en'),

         (: optional argument provides instance for selection of DTS to get right label :)
         xfi:concept-label( QName('http://abc.com/test','A'),'','','en', /xbrli:xbrl ),
         xfi:concept-label( QName('http://abc.com/test','A'),'','','en', $inst2 )
        )
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         (: node provides correct instance for function to select right DTS and label :)
         $result[1] eq 'det 1 a' and
         $result[2] eq 'det 2 a' and

         (: target instance DTS for label :)
         $result[3] eq 'det 1 a' and

         (: optional argument provides instance for selection of DTS to get right label :)
         $result[4] eq 'det 1 a' and
         $result[5] eq 'det 2 a' 
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-08">
    <name>Two function calls to same href return identical instance node</name>
    <documentation>
      <xhtml:p>
         Same test as function definition uses from that of XPath 2's definition of fn:doc()
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1c.xsd"/>
      <instance readMeFirst="true" id="V08" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V08">
        xfi:xbrl-instance('xbrl-inst-facts-instance2.xml') is
          xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         $result eq true()
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-09">
    <name>Two function calls to different href return different instance node</name>
    <documentation>
      <xhtml:p>
         Opposite of v-08
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1c.xsd"/>
      <instance readMeFirst="true" id="V09" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V09">
        xfi:xbrl-instance('xbrl-inst-facts-instance1-no-formula.xml') is
          xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         $result eq false()
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-10">
    <name>Function call to same href as target instance returns identical instance node as target instance</name>
    <documentation>
      <xhtml:p>
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1c.xsd"/>
      <instance readMeFirst="true" id="V10" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V10">
        xfi:xbrl-instance('xbrl-inst-facts-instance1-no-formula.xml') is
          /xbrli:xbrl
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         $result eq true()
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-11">
    <name>Multiple function calls to same href return identical instance node</name>
    <documentation>
      <xhtml:p>
        There must be 3 unique nodes (xbrli:xbrl) in the sequence of returned instances.
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1c.xsd"/>
      <instance readMeFirst="true" id="V11" xlink:type="simple" xlink:href="xbrl-inst-detached-labels-instance1-no-formula.xml"/>
     <cfcn:call file="V11">
        for $loopCount in (1 to 1000),
            $href in (
              'xbrl-inst-detached-labels-instance2.xml',
              'xbrl-inst-facts-instance1-no-formula.xml',
              'xbrl-inst-facts-instance2.xml'
            ) return xfi:xbrl-instance($href)
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         count ($result intersect $result) eq 3
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-12">
    <name>Diff all facts between two instances</name>
    <documentation>
      <xhtml:p>
        Compare facts between instances
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1.xsd"/>
      <instance readMeFirst="true" id="V12" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V12">
        for $inst2 in xfi:xbrl-instance('xbrl-inst-facts-instance2.xml'),
            $inst1Fact in //*[namespace-uri() eq 'http://abc.com/test1'],
            $inst2Fact in $inst2/*[namespace-uri() eq 'http://abc.com/test2' and
                                   local-name() eq local-name($inst1Fact)]
            return ($inst2Fact - $inst1Fact)
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         count( $result ) eq 18 and
         $result[1] eq 3000000 and
         $result[2] eq 3030000 and
         $result[3] eq 3030300 and
         $result[4] eq 3030303 and
         $result[5] eq 3030303 and
         $result[6] eq 3030303 and
         $result[7] eq 3030300 and
         $result[8] eq 3030303 and
         $result[9] eq 3030303 and
         $result[10] eq 3030300 and
         $result[11] eq 3030010 and
         $result[12] eq 3030300 and
         $result[13] eq 3030303 and
         $result[14] eq 3030000 and
         $result[15] eq 3000000 and
         $result[16] eq 3030000 and
         $result[17] eq 3000000 and
         $result[18] eq 3030000
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-13">
    <name>Diff specified fact between two instances using element()</name>
    <documentation>
      <xhtml:p>
        Compare facts between instances.
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1.xsd"/>
      <instance readMeFirst="true" id="V13" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V13">
        for $inst2 in xfi:xbrl-instance('xbrl-inst-facts-instance2.xml') return
         ( //test1:A - $inst2/element(test2:A) ,
           //test1:A2 - $inst2/element(test2:A2) )
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         count( $result ) eq 2 and
         $result[1] eq -3000000 and
         $result[2] eq -3030010
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-14">
    <name>Two function calls to same href return identical child instance node</name>
    <documentation>
      <xhtml:p>
        Same as V-09 but for twice-loaded (but identical) instance fact
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1c.xsd"/>
      <instance readMeFirst="true" id="V14" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V14">
        xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')/test2:A11 is
          xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')/test2:A11
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         $result eq true()
      </cfcn:test>
    </outputs>
  </variation>

  <variation id="V-15">
    <name>Two function calls to different href return different instance node</name>
    <documentation>
      <xhtml:p>
        Same as V-09 but for duplicated (but separately different) instance fact
      </xhtml:p>
    </documentation>
      
    <inputs>
      <schema xlink:type="simple" xlink:href="xbrl-inst-test1c.xsd"/>
      <instance readMeFirst="true" id="V15" xlink:type="simple" xlink:href="xbrl-inst-facts-instance1-no-formula.xml"/>
     <cfcn:call file="V15">
        xfi:xbrl-instance('xbrl-inst-facts-instance2.xml')/test2:A11 is
          xfi:xbrl-instance('xbrl-inst-facts-instance2-clone.xml')/test2:A11
      </cfcn:call>
    </inputs>
    <outputs>
      <cfcn:test>
         $result eq false()
      </cfcn:test>
    </outputs>
  </variation>

  <revisions>
    <reg:revision on="2008-12-12T00:00:00" by="herm">
      <xhtml:p>
        Created the test case.
      </xhtml:p>
    </reg:revision>
    <reg:revision on="2011-06-22T00:00:00" by="herm">
      <xhtml:p>
        Added xmlns:xs.
      </xhtml:p>
    </reg:revision>
  </revisions>

</testcase>




